From: cl349@firebug.cl.cam.ac.uk Date: Wed, 14 Sep 2005 19:22:31 +0000 (+0000) Subject: Add store function. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~16806^2~7 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=e995abd49438fea7aab1d10307dd35d30d1a71a9;p=xen.git Add store function. Signed-off-by: Christian Limpach --- diff --git a/tools/python/xen/xend/xenstore/xstransact.py b/tools/python/xen/xend/xenstore/xstransact.py index 08e3d9626a..378dd179cb 100644 --- a/tools/python/xen/xend/xenstore/xstransact.py +++ b/tools/python/xen/xend/xenstore/xstransact.py @@ -121,6 +121,20 @@ class xstransact: return ret[0] return ret + def store(self, *args): + for tup in args: + if len(tup) == 2: + (key, val) = tup + try: + fmt = { str : "%s", + int : "%i", + float : "%f" }[type(val)] + except KeyError: + raise TypeError + else: + (key, val, fmt) = tup + self.write(key, fmt % val) + def Read(cls, path, *args): while True: @@ -216,3 +230,22 @@ class xstransact: raise Gather = classmethod(Gather) + + def Store(cls, path, *args): + while True: + try: + t = cls(path) + v = t.store(*args) + t.commit() + return v + except RuntimeError, ex: + t.abort() + if ex.args[0] == errno.ETIMEDOUT: + pass + else: + raise + except: + t.abort() + raise + + Store = classmethod(Store)